﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplication2.Class;
using System.Net.Http;
using System.Net.Http.Headers;

namespace WebApplication2
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        
             int language = 0;
             int TreatmentID = 0;
             
             string value = "Please Select One..";
        protected void Page_Load(object sender, EventArgs e)
        {
            language = (int)Session["Language"];
            TreatmentID = (int)Session["treatmentID"];
            if (!IsPostBack)
            {

                GetFormLabel();
                GetFormLabelPreparatory();
                GetFormLabelPost();
                GetPreHDdata();
                GetFormDataPreparatory();
                GetFormDataPost();
                
             }
            ddlBP.Items.Add(value);
            ddlbpPulse.Items.Add(value);
            DDL1stSite.Items.Add(value);
            DDL1stType.Items.Add(value);
            ddl2ndsite.Items.Add(value);
            ddl2ndtype.Items.Add(value);
            ddlMonility.Items.Add(value);
            ddlAssementby.Items.Add(value);
            ddlModified.Items.Add(value);
        }

       

        public void GetFormLabel()
        {
            

            WebRequest req = WebRequest.Create("http://192.168.1.156/api/FMTXPreHDLabel?LanguageID=" + language);
            req.ContentType = "application/json";
            WebResponse resp = req.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader re = new StreamReader(stream);
            String json = re.ReadToEnd();
            // json = "{\"FMTXPreHDLabel\":" + json + "}";
            JavaScriptSerializer ser = new JavaScriptSerializer();
            List<FMTXPreHDLabel> keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPreHDLabel>>(json);
            //   JavaScriptSerializer ser = new JavaScriptSerializer();
            // var keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<KeyWrapperPreHDLabel>(json);
           
            

            foreach (var item in keysWrapper)
            {
                if (item.FormLabelCode == "TxSc1-GpPreAss1")
                {
                    lblPreAssess.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Wt")
                {
                    lblWeight.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Wtkg")
                {
                    lblkg.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Unfitwt")
                {
                    lblUnfit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-BP")
                {
                    lblBP.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-PR")
                {
                    lblPulse.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-PRhy-R")
                {
                    lblReuglar.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-PRhy-I")
                {
                    lblirregular.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-BPP")
                {
                    lblBPpulse.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Temp")
                {
                    lblTemperature.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-RR")
                {
                    lblRespiration.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Breath")
                {
                    lblBreathSound.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-BrVes")
                {
                    lblvesicular.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-BrAbn")
                {
                    lblAbnormal.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Edema")
                {
                    Label2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-EdmAbs")
                {
                    lblAbsent.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-EdmPres")
                {
                    lblPresent.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Mstatus")
                {
                    lblMental.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-MstOr")
                {
                    lblOriented.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-MstAbn")
                {
                    lblmentalAb.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Pain")
                {
                    Label3.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-PainAbs")
                {
                    lblPainAbsent.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-PainPre")
                {
                    lblpainPresent.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Complaints")
                {
                    Label4.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Compyes")
                {
                    lblICYes.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-CompNo")
                {
                    lblICno.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Mob")
                {
                    lblMobility.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-1Access")
                {
                    lbl1Access.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-2Access")
                {
                    lbl2nd.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-GpFist")
                {
                    FistulaGraft.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Bruit")
                {
                    lblBruit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-BruitPre")
                {
                    lblBruit1.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-BruitAbn")
                {
                    lblBruit2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Thrill")
                {
                    lblThrill.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-ThrillPre")
                {
                    lblThrill1.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-ThrillAbn")
                {
                    lblThrill2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-limbred")
                {
                    lblInfection.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-limbAbs")
                {
                    lblInfection1.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-limbPre")
                {
                    lblInfection2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-needle")
                {
                    Nesize.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-ndle-art")
                {
                    Art.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-ndle-ven")
                {
                    Ven.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-cannulate")
                {
                    Cannulationattempts.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-GpCath")
                {
                    lblcath.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-aport")
                {
                    lblartport.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-vport")
                {
                    lblvenPort.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-clots")
                {
                    lblClots.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-clotsAYes")
                {
                    lblClotsYes.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-clotsANo")
                {
                    lblClotsAN.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-clotsVYes")
                {
                    lblClotsVY.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-clotsVNo")
                {
                    lblClotsVN.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-patent")
                {
                    lblpatent.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-patAYes")
                {
                    lblpatentAY.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-patANo")
                {
                    lblpatentAN.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-patVYes")
                {
                    lblpatentVY.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-patVNo")
                {
                    lblpatentVN.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-exit")
                {
                    lblexitsite.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-clean")
                {
                    lblCleanDry.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-redness")
                {
                    lblRedness.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-discharge")
                {
                    lblDischages.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-others")
                {
                    lblbOthers.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-cflow")
                {
                    lblFlow.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-norm")
                {
                    lblFlowN.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-rev")
                {
                    lblfLOWf.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-date")
                {
                    lbldoi.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-dateUn")
                {
                    btnUnset.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-GpPreData")
                {
                    lblPreHD.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-ODW")
                {
                    lblDryWeight.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-ODWkg")
                {
                    lblweightkg.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-OTUF")
                {
                    lblTargetUf.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-OTUF")
                {
                    lblTargetUf.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-OTUFL")
                {
                    lblufL.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-IDWG")
                {
                    lblIDWG.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Wtchg")
                {
                    lblweightchange.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Wtchgkg")
                {
                    lblIDWGkg.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Wtchgkg")
                {
                    lblweighchangekg.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-pfluid")
                {
                    lblpfi.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-pfluidml")
                {
                    lblpfiml.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-dwloss")
                {
                    lblweighloss.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-dwlosskg")
                {
                    lbllosskg.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-dur")
                {
                    lblDuration.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-durhr")
                {
                    lbldurationhr.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Saline")
                {
                    lblsaline.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Salml")
                {
                    lblsalineml.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-TUF")
                {
                    lbltfr.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-TUFml")
                {
                    lbltfrml.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-QB")
                {
                    lblbloodflow.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Qbu")
                {
                    lblbfml.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-UFR")
                {
                    lblUFRate.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-UFRu")
                {
                    lblUFml.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Qd")
                {
                    lblDialysis.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Qdu")
                {
                    lbldialysisml.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "TxSc1-GpPreNotes")
                {
                    lblNursingNote.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Aprob")
                {
                    lblAcessPrblem.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Ix")
                {
                    lblInvest.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Ixdone")
                {
                    lblDone.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Ixnotdone")
                {
                    lblReasonNotDone.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-PreCom")
                {
                    lblComments.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Assessby")
                {
                    lblAssessmentby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc1-Modby")
                {
                    lblModified.Text = item.Language.ToString();
                }

                //DownDropList
                
                if (item.BPPositionID != 0)
                {
                   
                    if (item.BP_Language != "")
                    {
                        
                        ddlBP.Items.Add(item.BP_Language.ToString());
                    }
                    
                }
                if (item.BPPositionID != 0)
                {
                    
                    ddlbpPulse.Items.Add(item.BP_Language.ToString());
                }
                if (item.Access_SiteID != 0)
                {
                    DDL1stSite.Items.Add(item.Access_Site_Language.ToString());
                }
                if (item.Access_TypeID != 0)
                {
                    DDL1stType.Items.Add(item.Access_Type_Language.ToString());
                }
                if (item.Access_SiteID != 0)
                {
                    ddl2ndsite.Items.Add(item.Access_Site_Language.ToString());
                }
                if (item.Access_TypeID != 0)
                {
                    ddl2ndtype.Items.Add(item.Access_Type_Language.ToString());
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials.ToString() != "")
                    {
                        ddlAssementby.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials.ToString() != "")
                    {
                        ddlModified.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.MobilityID != 0)
                {

                    ddlMonility.Items.Add(item.Mobility_Language.ToString());
                }




            }
        }

        public void GetPreHDdata()
        {
            TreatmentID = (int)Session["treatmentID"];
            WebRequest req = WebRequest.Create("http://192.168.1.156/api/FMTXPreHD?HDTreatmentID=" + TreatmentID);
            req.ContentType = "application/json";
            WebResponse resp = req.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader re = new StreamReader(stream);
            String json = re.ReadToEnd();

            JavaScriptSerializer ser = new JavaScriptSerializer();
            //  PreHD keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<PreHD>(json);
            //  var keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<KeyWrapperPreHD>(json);
            // object obje = ser.Deserialize<PreHD>(json);

            var obj = JObject.Parse(json);

            TextBox1.Text = (obj["Weight"]).ToString();
            tbxbp1.Text = (obj["BP_dias"]).ToString();
            tbxbp2.Text = (obj["BP_sys"]).ToString();
            tbxbf.Text = (obj["Blood_Flow"]).ToString();
            tbxcannuation.Text = (obj["CannualationAttempts"]).ToString();
            tbxDuration.Text = (obj["Dialysis_Duration"]).ToString();
            tbxdialysis.Text = (obj["Dialysis_Flow"]).ToString();
            tbxpfi.Text = (obj["Planned_fluid_intake"]).ToString();
            tbxpulse1.Text = (obj["Pulse_Rate"]).ToString();
            //tbxpulse2.Text = (obj["Pulse_Rhythm"]).ToString();
            tbxbppulse1.Text = (obj["BP_sys2"]).ToString();
            tbxbppulse2.Text = (obj["BP_dias2"]).ToString();
            tbxbppulse3.Text = (obj["Pulse_Rate2"]).ToString();
            tbxrespiration.Text = (obj["Respiration_Rate"]).ToString();
            TextBox5.Text = (obj["Target_UF"]).ToString();
            tbxDryWeight.Text = (obj["Target_Weight"]).ToString();
            TextBox2.Text = (obj["Temperature"]).ToString();
            tbxUF.Text = (obj["UF"]).ToString();
            tbxweightchange.Text = (obj["Weight_Changge"]).ToString();
            tbxComments.Text = (obj["pre_comments"]).ToString();
            tbxsaline.Text = (obj["saline"]).ToString();
            tbctfr.Text = (obj["total_fluid_removal"]).ToString();
            tbxweighloss.Text = (obj["weightLoss"]).ToString();
            tbxreasonNot.Text = (obj["ReasonsForNotDone"]).ToString();
            TextBox3.Text = (obj["Needle_Gauge_Arterial"]).ToString();
            TextBox4.Text = (obj["Needle_Gauge_Arterial"]).ToString();

            if (Convert.ToDateTime(obj["Date_Insertion"]) != DateTime.MinValue)
            {
                DateForInsertion.Value = (obj["Date_Insertion"]).ToString();
            }
            if (Convert.ToDateTime(obj["AssessmentDate"]) != DateTime.MinValue)
            {
                AssessmentDate.Value = (obj["AssessmentDate"]).ToString();
            }
            if (Convert.ToDateTime(obj["ModifiedDate"]) != DateTime.MinValue)
            {
                ModifiedDate.Value = (obj["ModifiedDate"]).ToString();
            }


            //checkboxes

            if ((obj["Pulse_Rhythm"]).ToString() == "Regular")
            {
                regular.Checked = true;
            }
            if ((obj["Pulse_Rhythm"]).ToString() == "Irregular")
            {
                irregular.Checked = true;
            }

            if ((obj["Breath_sounds"]).ToString() == "Vesicular")
            {
                cbVesicular.Checked = true;
            }
            if ((obj["Breath_sounds"]).ToString() == "Abnormal")
            {
                Abnormal.Checked = true;
            }
            if ((obj["Bruit"]).ToString() == "Present")
            {
                cbBruit1.Checked = true;
            }
            if ((obj["Bruit"]).ToString() == "Abnormal")
            {
                cbBruit2.Checked = true;
            }
            if ((obj["Thrill"]).ToString() == "Present")
            {
                cbThrill1.Checked = true;
            }
            if ((obj["Thrill"]).ToString() == "Abnormal")
            {
                cbThrill2.Checked = true;
            }
            if ((obj["AccessLimb"]).ToString() == "Present")
            {
                cbInfection1.Checked = true;
            }
            if ((obj["AccessLimb"]).ToString() == "Abnormal")
            {
                cbInfection2.Checked = true;
            }
            if ((obj["Edema"]).ToString() == "Absent")
            {
                Absent.Checked = true;
            }
            if ((obj["Edema"]).ToString() == "Present")
            {
                Present.Checked = true;
            }
            if ((obj["Mental_status"]).ToString() == "Oriented")
            {
                Oriented.Checked = true;
            }
            if ((obj["Mental_status"]).ToString() == "Abnormal")
            {
                Abnormalmental.Checked = true;
            }
            if ((obj["Pain"]).ToString() == "Absent")
            {
                AbsentPain.Checked = true;
            }
            if ((obj["Pain"]).ToString() == "Present")
            {
                painPresent.Checked = true;
            }
            if ((obj["Interdialysis_Complaint"]).ToString() == "Yes")
            {
                ICYes.Checked = true;
            }
            if ((obj["Interdialysis_Complaint"]).ToString() == "No")
            {
                ICno.Checked = true;
            }
            if ((obj["Cather_Art_Clots"]).ToString() == "Yes")
            {
                cbClotsYes.Checked = true;
            }
            if ((obj["Cather_Art_Clots"]).ToString() == "No")
            {
                cbClotsAN.Checked = true;
            }
            if ((obj["Cather_Ven_Clots"]).ToString() == "Yes")
            {
                cbClotsVY.Checked = true;
            }
            if ((obj["Cather_Ven_Clots"]).ToString() == "No")
            {
                cbClotsVN.Checked = true;
            }
            if ((obj["Cather_Art_Patent"]).ToString() == "Yes")
            {
                cbpatentAY.Checked = true;
            }
            if ((obj["Cather_Art_Patent"]).ToString() == "No")
            {
                cbpatentAN.Checked = true;
            }
            if ((obj["Cather_Ven_Patent"]).ToString() == "Yes")
            {
                cbpatentVY.Checked = true;
            }
            if ((obj["Cather_Ven_Patent"]).ToString() == "No")
            {
                cbpatentVN.Checked = true;
            }
            if ((obj["IsCather_ExitSite_Clean"]).ToString() == "True")
            {
                cbCleanDry.Checked = true;
            }
            if ((obj["IsCather_ExitSite_Discharges"]).ToString() == "True")
            {
                cbDischages.Checked = true;
            }
            if ((obj["IsCather_ExitSite_Others"]).ToString() == "True")
            {
                cbOthers.Checked = true;
            }
            if ((obj["IsCather_ExitSite_Redness"]).ToString() == "True")
            {
                cbRedness.Checked = true;
            }
            if ((obj["Cather_Flow"]).ToString() == "Normal")
            {
                cbFlowN.Checked = true;
            }
            if ((obj["Cather_Flow"]).ToString() == "Reverse")
            {
                cbfLOWf.Checked = true;
            }
            if ((obj["isUnfitWeight"]).ToString() == "True")
            {
                unift.Checked = true;
            }
            if ((obj["IsDoneInvestigation"]).ToString() == "True")
            {
                cbDone.Checked = true;
            }
            decimal Last_Post_Weight = Convert.ToDecimal(obj["Last_Post_Weight"]);
            decimal weight = Convert.ToDecimal(obj["weight"]);
            decimal IDWG = Last_Post_Weight - weight;
            tbxidwg.Text = IDWG.ToString();
            //DropDownList
            WebRequest req1 = WebRequest.Create("http://192.168.1.156/api/FMTXPreHDLabel?LanguageID=" + language);
            req1.ContentType = "application/json";
            WebResponse resp1 = req1.GetResponse();
            Stream stream1 = resp1.GetResponseStream();
            StreamReader re1 = new StreamReader(stream1);
            String json1 = re1.ReadToEnd();
            // json = "{\"FMTXPreHDLabel\":" + json + "}";
            JavaScriptSerializer ser1 = new JavaScriptSerializer();
            List<FMTXPreHDLabel> keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPreHDLabel>>(json1);

            int AccessSite1ID = Convert.ToInt32(obj["Access_Site1ID"]);
            int AccessSite2ID = Convert.ToInt32(obj["Access_Site2ID"]);
            int AccessType1ID = Convert.ToInt32(obj["Access_Type1ID"]);
            int AccessType2ID = Convert.ToInt32(obj["Access_Type2ID"]);
            int AssessmentBy = Convert.ToInt32(obj["Assessment_by"]);
            int BPpositionID = Convert.ToInt32(obj["BP_Position"]);
            int BPpostionID2 = Convert.ToInt32(obj["BP_Position2"]);
            int ModifiedBy = Convert.ToInt32(obj["ModifiedBy"]);
            int Mobility = Convert.ToInt32(obj["Mobility"]);


            foreach (var item in keysWrapper)
            {
            //    if (item.Access_SiteID != 0)
               // {
                if (item.Access_SiteID == AccessSite1ID && AccessSite1ID != 0)
                {
                    DDL1stSite.Text = item.Access_Site_Language.ToString();
                }
                else
                {
                    DDL1stSite.Text = value;
                }



                if (item.Access_SiteID == AccessSite2ID && AccessSite2ID != 0)
                {
                    ddl2ndsite.Text = item.Access_Site_Language.ToString();
                }
                else
                {
                    ddl2ndsite.Text = value;
                }
              //  }
               
             //   if (item.Access_TypeID != 0)
              //  {
                if (item.Access_TypeID == AccessType1ID && AccessType1ID != 0)
                {
                    DDL1stType.Text = item.Access_Type_Language.ToString();
                }
                else
                {
                    DDL1stType.SelectedIndex = 0;
                }
                if (item.Access_TypeID == AccessType2ID && AccessType2ID !=0)
                {
                    ddl2ndtype.Text = item.Access_Type_Language.ToString();
                }
                else
                {
                    ddl2ndtype.Text = value;
                }
               // }
            //    if (item.User_Id != 0)
             //   {
                if (item.User_Id == AssessmentBy && AssessmentBy != 0)
                {
                    ddlAssementby.Text = item.Initials.ToString();
                }
                else
                {
                    ddlAssementby.Text = value;
                }
                if (item.User_Id == ModifiedBy && ModifiedBy != 0)
                {
                    ddlModified.Text = item.Initials.ToString();
                }
                else
                {
                    ddlModified.Text = value;
                }
             //   }
               // if (item.BPPositionID != 0)
              //  {
                if (item.BPPositionID == BPpositionID && BPpositionID != 0)
                {
                    ddlBP.Text = item.BP_Language.ToString();
                }
                else
                {
                    ddlBP.SelectedIndex = 0;
                }
                if (item.BPPositionID == BPpostionID2 && BPpostionID2 != 0)
                {
                    ddlbpPulse.Text = item.BP_Language.ToString();
                }
                else
                {
                    ddlbpPulse.Text = value;
                }
              //  }
              //  if (item.MobilityID != 0)
             //   {
                if (item.MobilityID == Mobility && Mobility != 0)
                {
                    ddlMonility.Text = item.Mobility_Language.ToString();
                }
                else
                {
                    ddlMonility.Text = value;
                }
             //   }


                string  PatientID = (obj["PatientID"]).ToString();
                Session["PatientID"] = PatientID;

            }

        }

        public void GetFormLabelPreparatory()
        {
            WebRequest req = WebRequest.Create("http://192.168.1.156/api/FMTXPreparatoryLabel?LanguageID=" + language);
            req.ContentType = "application/json";
            WebResponse resp = req.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader re = new StreamReader(stream);
            String json = re.ReadToEnd();
            // json = "{\"FMTXPreHDLabel\":" + json + "}";
            JavaScriptSerializer ser = new JavaScriptSerializer();
            List<FMTXPreparatoryLabel> keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPreparatoryLabel>>(json);
            //   JavaScriptSerializer ser = new JavaScriptSerializer();
            // var keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<KeyWrapperPreHDLabel>(json);
            foreach (var item in keysWrapper)
            {
                if (item.FormLabelCode == "Tx-Sc2-GpPrep")
                {
                    lblPreparatory.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Chair")
                {
                    lblStation.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-ROW")
                {
                    lblRO.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-MID")
                {
                    lblMachineID.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Mtype")
                {
                    lblType.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Sched")
                {
                    lblSchedule.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Shift")
                {
                    lblshift.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Dialyser")
                {
                    lblDialyser.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Useno")
                {
                    lbluseno.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Max")
                {
                    Max.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Dialysate")
                {
                    lbldialysate.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Aconc")
                {
                    lblConA.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Bconc")
                {
                    lblConB.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Qd")
                {
                    Label7.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Cflow")
                {
                    lblCounterflow.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Cflowyes")
                {
                    lblCouterYes.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Cflowno")
                {
                    lblCouterNo.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Dtemp")
                {
                    Label8.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Cond")
                {
                    lblCondu.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-pH")
                {
                    lblPH.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-GpAC")
                {
                    lblAntocoa.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Atype")
                {
                    lblAntiType.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Primeyes")
                {
                    lblTypeYes.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Primeno")
                {
                    lblTypeNo.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Bolus")
                {
                    lblBolus.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Mdose")
                {
                    lblMiddose.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Load")
                {
                    lblLoad.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Prepared")
                {
                    lblPreparedby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Given")
                {
                    lblGivenby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Atime")
                {
                    lbltime.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-infusion")
                {
                    lblInfusion.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-infurate")
                {
                    lblInfusionUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Timeoff")
                {
                    lblTimeOff.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Timemin")
                {
                    lbltimeoffUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-GpRQC")
                {
                    lblReprocQC.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-PreProcess")
                {
                    lblPreprocess.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-PreTx")
                {
                    lblTreatment.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Rtech")
                {
                    lblReuse.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-ATCby")
                {
                    lblCheckby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Alarm")
                {
                    lblAlarmTest.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-ATPass")
                {
                    lblPass.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Dpress")
                {
                    lblPressure.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-DPTPass")
                {
                    lblPresPass.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Mproc")
                {
                    lblManual.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-match")
                {
                    lblCorrect.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-witness")
                {
                    lblWitenessBy.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-witness")
                {
                    lblWitnessby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-GpDC")
                {
                    lblDialyserSetUp.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-DPR")
                {
                    lblPrior.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-DPRpos")
                {
                    lblPositive.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-DPRpos")
                {
                    lblPositive.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-SCheckCby")
                {
                    lblCheckby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDT")
                {
                    lblResidualTest.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDTD")
                {
                    lblDialyserN.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDTDneg")
                {
                    tbxDialyNegative.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDTM")
                {
                    lblMachine.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDTMNa")
                {
                    lblNA.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDTMNeg")
                {
                    lblNegative2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDTB")
                {
                    lblBloodline.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDTBNeg")
                {
                    lblNegative3.Text = item.Language.ToString();
                }
                

                if (item.FormLabelCode == "Tx-Sc2-RDTS")
                {
                    lblsalinebag.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-RDTSNeg")
                {
                    lblNegative4.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Start")
                {
                    lblStartTime.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-primeby")
                {
                    lblPrimeby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-dialyby")
                {
                    lblCommenced.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Com")
                {
                    lblPrepComments.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Compby")
                {
                    lblComleteby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Modby")
                {
                    Label9.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-GpRQC4")
                {
                    lblChange.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-2MID")
                {
                    lbl2ndMachineID.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-mtime")
                {
                    lblTimeChanged.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-mhhmm")
                {
                    lblhhmm.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-2Dialyser")
                {
                    lbl2ndDialyser.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-dtime")
                {
                    lblTimeChange2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-dhhmm")
                {
                    lblhhmm2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-reason")
                {
                    lblReasonChange.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-change")
                {
                    lblChangeBy.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc2-Schecks")
                {
                    lblsterilant.Text = item.Language.ToString();
                }
                if (item.ScheduleID != 0)
                {
                    ddlSchedule.Items.Add(item.Schedule_Frequency.ToString());
                }
                if (item.ShiftID != 0)
                {
                    ddlShift.Items.Add(item.Shift.ToString());
                }
                if (item.ChairID != 0)
                {
                    ddlstation.Items.Add(item.Chair_Name.ToString());
                }
                if (item.MachineCodeID != 0)
                {
                    if (item.Machine_Language != "")
                    {
                        ddlMachineID.Items.Add(item.MachineID2.ToString());
                    }
                }
                if (item.MachineCodeID != 0)
                {
                    if (item.MachineID2 != "")
                    {
                        ddl2ndMachineID.Items.Add(item.MachineID2.ToString());
                    }
                }
                if (item.DialyserID != 0)
                {
                    ddldialyser.Items.Add(item.Dialyser_Name.ToString());
                }
                if (item.DialyserID != 0)
                {
                    dd2ndDialyser.Items.Add(item.Dialyser_Name.ToString());
                }
                if (item.MachineID != 0)
                {
                    DropDownList3.Items.Add(item.Machine_Language.ToString());
                }
                if (item.HepTypeID != 0)
                {
                    ddlAntiType.Items.Add(item.HepLanguage.ToString());
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlChangeby.Items.Add(item.Initials.ToString());
                    }

                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlCommencedBy.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlCompleteby.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlModifiedBy.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlalarmCheck.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlReuse.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlManualCheck.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlNegative2Check.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlNegative3Check.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlNegativeCheck.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlPositiveCheckby.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlpressureCheckby.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlprimedby.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlSalineNegativeCheck.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlWitessnessby.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.ReasonID != 0)
                {
                    ddlReasonForchange.Items.Add(item.Reason_Language.ToString());
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlpreparebybou.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlpreparebyMid.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlwitessblous.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlwitenessMid.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlGivenByBolu.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlGivenByMid.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.DialysateID != 0)
                {
                    ddldialysate.Items.Add(item.Dialysate_Name.ToString());
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlCorrect.Items.Add(item.Initials.ToString());
                    }
                }
            }
        }

        public void GetFormDataPreparatory()
        {
            TreatmentID = (int)Session["treatmentID"];
            WebRequest req = WebRequest.Create("http://192.168.1.156/api/FMTXPreparatory?HDTreatmentID=" + TreatmentID);
            req.ContentType = "application/json";
            WebResponse resp = req.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader re = new StreamReader(stream);
            String json = re.ReadToEnd();

            JavaScriptSerializer ser = new JavaScriptSerializer();


            var obj = JObject.Parse(json);
            tbxRO.Text = (obj["ROWater"]).ToString();
            tbxuseno.Text = (obj["UseNo"]).ToString();
            tbxmax.Text = (obj["Dialyser_ReuseNo"]).ToString();

            tbxconA.Text = (obj["DialysateAconc"]).ToString();
            tbxConB.Text = (obj["DialysateBconc"]).ToString();
            tbxflow.Text = (obj["Dialysis_Flow"]).ToString();
            tbxTemperature.Text = (obj["Dialysate_Temp"]).ToString();
            tbxPH.Text = (obj["Dialysate_PH"]).ToString();
            tbxcondu.Text = (obj["Conductivity"]).ToString();
            tbxload.Text = (obj["Actual_Heparin_bolus"]).ToString();
            tbxloadmid.Text = (obj["Heparine_Mid_Dose"]).ToString();

            if (Convert.ToDateTime(obj["HD_Run_Bolus_Time"]) != DateTime.MinValue)
            {
                tbxtime.Text = (obj["HD_Run_Bolus_Time"]).ToString();
            }
            if (Convert.ToDateTime(obj["HD_Run_MidDose_Time"]) != DateTime.MinValue)
            {
                tbxtimeMid.Text = (obj["HD_Run_MidDose_Time"]).ToString();

            }
            //if ((obj["HD_Run_Start_time2"]) == DBNull.Value)
            //{
            //    tbxStartTime.Text = Convert.ToDateTime(obj["HD_Run_Start_time2"]).ToString("HH:mm");
            //}
            if (Convert.ToDateTime(obj["Complete_DateTime"]) != DateTime.MinValue)
            {
                CompleteDate.Value = (obj["Complete_DateTime"]).ToString();
            }
            if (Convert.ToDateTime(obj["Modified_DateTime"]) != DateTime.MinValue)
            {
                ModifiedDate.Value = (obj["Modified_DateTime"]).ToString();
            }
            if (Convert.ToDateTime(obj["Time_Changed_Machine"]) != DateTime.MinValue)
            {
                tbxTimeChange.Text = (obj["Time_Changed_Machine"]).ToString();
            }
            if (Convert.ToDateTime(obj["Time_Changed_dialyser"]) != DateTime.MinValue)
            {
                tbxTimeChange2.Text = (obj["Time_Changed_dialyser"]).ToString();
            }

            tbxprepComments.Text = (obj["HDMac_Comments"]).ToString();

            //checkboxes

            // cbCFYes

            if ((obj["Counter_Flow"]).ToString() == "Yes")
            {
                cbCFYes.Checked = true;
            }
            //   cbCFNo
            if (obj["Counter_Flow"].ToString() == "No")
            {
                cbCFNo.Checked = true;
            }
            // cbpreprocess

            if (obj["IsDialyserPreProcess"].ToString() == "True")
            {
                cbpreprocess.Checked = true;
            }

            //cbtreatment
            if (obj["IsDialyserPreTreat"].ToString() == "True")
            {
                cbtreatment.Checked = true;
            }
            //cbAlarmTest
            if (obj["Alarm_Tests"].ToString() == "Pass")
            {
                cbAlarmTest.Checked = true;
            }
            //cbPressure
            if (obj["Dialyser_Pressure_Test"].ToString() == "Pass")
            {
                cbPressure.Checked = true;
            }

            //cbTypeYes
            if (obj["IsPrime"].ToString() == "True")
            {
                cbTypeYes.Checked = true;
            }
            //cbTypeNo
            if (obj["IsPrime"].ToString() == "False")
            {
                cbTypeNo.Checked = true;
            }
            //cbPriprPositive
            if (obj["Disinfectant_Prior_To_Rinse"].ToString() == "Positive")
            {
                cbPriprPositive.Checked = true;
            }
            //cbNegative1
            if (obj["Residual_Disinfectant_Test"].ToString() == "Negative")
            {
                cbNegative1.Checked = true;
            }
            //cbMachineNA
            if (obj["Residual_Machine_Test"].ToString() == "")
            {
                cbMachineNA.Checked = true;
            }
            //cbNegative2

            if (obj["Residual_Machine_Test"].ToString() == "Negative")
            {
                cbNegative2.Checked = true;
            }
            //cbNegativeBlood
            if (obj["Residual_Bloodline_Test"].ToString() == "Negative")
            {
                cbNegativeBlood.Checked = true;
            }

            //cbsalineNegative
            if (obj["Residual_SalineBag_Test"].ToString() == "Negative")
            {
                cbsalineNegative.Checked = true;
            }

            //cbcompleteby



            //DropDownList
            WebRequest req1 = WebRequest.Create("http://192.168.1.156/api/FMTXPreparatoryLabel?LanguageID=" + language);
            req1.ContentType = "application/json";
            WebResponse resp1 = req1.GetResponse();
            Stream stream1 = resp1.GetResponseStream();
            StreamReader re1 = new StreamReader(stream1);
            String json1 = re1.ReadToEnd();
            // json = "{\"FMTXPreHDLabel\":" + json + "}";
            JavaScriptSerializer ser1 = new JavaScriptSerializer();
            List<FMTXPreparatoryLabel> keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPreparatoryLabel>>(json1);

            int stationID = Convert.ToInt32(obj["Chair"]);
            int MachineID = Convert.ToInt32(obj["MachineCode"]);
            int type = Convert.ToInt32(obj["Machine_Type"]);
            int schedule = Convert.ToInt32(obj["Schedule"]);
            int Shift = Convert.ToInt32(obj["Shift"]);
            int Dialyser = Convert.ToInt32(obj["First_Dialyser"]);
            int Dialysate = Convert.ToInt32(obj["First_Dialysate"]);
            int reuse = Convert.ToInt32(obj["Reuse_Tech"]);
            int AlarmTest = Convert.ToInt32(obj["AlarmTest_CheckBy"]);
            int pressureTest = Convert.ToInt32(obj["DPTTest_CheckBy"]);
            int mannual = Convert.ToInt32(obj["MP_CheckBy"]);
            int antiType = Convert.ToInt32(obj["HeparineTyp"]);
            int preparaby = Convert.ToInt32(obj["Bolus_Prepared_By"]);
            int preparabyMin = Convert.ToInt32(obj["MidDose_Prepared_By"]);
            int givenby = Convert.ToInt32(obj["Bolus_Administered_By"]);
            int givebyMid = Convert.ToInt32(obj["MidDose_Administered_By"]);
            int witnessby = Convert.ToInt32(obj["Bolus_Witnessed_By"]);
            int witnessbyMid = Convert.ToInt32(obj["MidDose_Witnessed_By"]);
            int CorrectDia = Convert.ToInt32(obj["Dialyser_Patient_ID_Match"]);
            int witnessbyDia = Convert.ToInt32(obj["DialyserCheck_WitnessBy"]);
            int PriorToR = Convert.ToInt32(obj["DPR_CheckBy"]);
            int DialyserCheck = Convert.ToInt32(obj["RDT_CheckBy"]);
            int machinecheck = Convert.ToInt32(obj["Residual_Machine_CheckedBy"]);
            int bloodline = Convert.ToInt32(obj["Residual_Bloodline_CheckedBy"]);
            int saline = Convert.ToInt32(obj["Residual_SalineBag_CheckedBy"]);
            int primeBy = Convert.ToInt32(obj["PrimedBy"]);
            int Commencedby = Convert.ToInt32(obj["DialysedBy"]);
            int completeby = Convert.ToInt32(obj["Completed_By"]);
            int Modifiedby = Convert.ToInt32(obj["Modified_By"]);
            int Secndmachine = Convert.ToInt32(obj["Second_Machine_ID"]);
            int SecndDialyser = Convert.ToInt32(obj["Second_Dialyser"]);
            int reasonChange = Convert.ToInt32(obj["ReasonForChanged"]);
            int ChangeBy = Convert.ToInt32(obj["ChagedBy"]);


            foreach (var item in keysWrapper)
            {   
                
                    if (reuse == item.User_Id && reuse !=0)
                    {
                        ddlReuse.Text = item.Initials.ToString();
                    }
                    if (AlarmTest == item.User_Id && AlarmTest !=0)
                    {
                        ddlalarmCheck.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == pressureTest && pressureTest!=0)
                    {
                        ddlpressureCheckby.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == mannual && mannual !=0)
                    {
                        ddlManualCheck.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == preparaby && preparaby !=0)
                    {
                        ddlpreparebybou.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == preparabyMin && preparabyMin !=0)
                    {
                        ddlpreparebyMid.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == givenby && givenby !=0)
                    {
                        ddlGivenByBolu.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == givebyMid && givebyMid !=0)
                    {
                        ddlGivenByMid.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == witnessby &&witnessby!=0)
                    {
                        ddlwitessblous.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == witnessbyMid && witnessbyMid !=0)
                    {
                        ddlwitenessMid.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == CorrectDia && CorrectDia !=0)
                    {
                        ddlCorrect.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == PriorToR && PriorToR !=0)
                    {
                        ddlPositiveCheckby.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == witnessbyDia && witnessbyDia !=0)
                    {
                        ddlWitessnessby.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == DialyserCheck && DialyserCheck !=0)
                    {
                        ddlNegativeCheck.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == machinecheck && machinecheck !=0)
                    {
                        ddlNegative2Check.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == bloodline && bloodline !=0)
                    {
                        ddlNegative3Check.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == saline && saline !=0)
                    {
                        ddlSalineNegativeCheck.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == primeBy && primeBy!=0)
                    {
                        ddlprimedby.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == Commencedby && Commencedby!=0)
                    {
                        ddlCommencedBy.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == completeby && completeby !=0)
                    {
                        ddlCompleteby.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == Modifiedby && Modifiedby !=0)
                    {
                        ddlModifiedBy.Text = item.Initials.ToString();
                    }
                    if (item.User_Id == ChangeBy && ChangeBy!=0)
                    {
                        ddlChangeby.Text = item.Initials.ToString();
                    }

                   
                        if (item.ChairID == stationID && stationID != 0)
                        {
                            ddlstation.SelectedValue = item.Chair_Name.ToString();
                        }
                    
                    
                    if (item.MachineCodeID == MachineID && MachineID !=0)
                    {
                        ddlMachineID.Text = item.MachineID2.ToString();
                    }
                    if (item.MachineID == type && type !=0)
                    {
                        DropDownList3.Text = item.Machine_Language.ToString();
                    }
                    if (item.ScheduleID == schedule&& schedule!=0)
                    {
                        ddlSchedule.Text = item.Schedule_Frequency.ToString();
                    }
                    if (item.ShiftID == Shift&& Shift!=0)
                    {
                        ddlShift.Text = item.Shift.ToString();
                    }
                    if (item.DialysateID == Dialyser && Dialyser!=0)
                    {
                        ddldialyser.Text = item.Dialyser_Name.ToString();
                    }
                    if (item.DialysateID == Dialysate&& Dialysate !=0)
                    {
                        ddldialysate.Text = item.Dialysate_Name.ToString();
                    }
                    if (item.HepTypeID == antiType && antiType!=0)
                    {
                        ddlAntiType.Text = item.HepLanguage.ToString();
                    }
                    if (item.MachineCodeID == Secndmachine && Secndmachine !=0)
                    {
                        ddl2ndMachineID.Text = item.MachineID2.ToString();
                    }
                    if (item.DialyserID == SecndDialyser && SecndDialyser!=0)
                    {
                        dd2ndDialyser.Text = item.Dialyser_Name.ToString();
                    }
                    if (item.ReasonID == reasonChange && reasonChange !=0)
                    {
                        ddlReasonForchange.Text = item.Reason_Language.ToString();
                       
                    }
                
            }

        }

        public void GetFormLabelPost()
        {
            
            WebRequest req = WebRequest.Create("http://192.168.1.156/api/FMTXPostHDLabel?LanguageID=" + language);
            req.ContentType = "application/json";
            WebResponse resp = req.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader re = new StreamReader(stream);
            String json = re.ReadToEnd();

            JavaScriptSerializer ser = new JavaScriptSerializer();
            List<FMTXPostHDLabel> keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPostHDLabel>>(json);

            foreach (var item in keysWrapper)
            {
                if (item.FormLabelCode == "Tx-Sc5-GpPostAss-1")
                {
                    lblPostAssess.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-PWt")
                {
                    Label10.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-PWtkg")
                {
                    Label11.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-unfit")
                {
                    Label12.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Wtloss")
                {
                    lblweightloss.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Wtlosskg")
                {
                    lblweightloggkg.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BP")
                {
                    Label13.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-PR")
                {
                    Label14.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Prhyr")
                {
                    lblregular.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Prhyi")
                {
                    Label15.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BPP")
                {
                    Label16.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Temp")
                {
                    lblTemperature2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-RR")
                {
                    lblRespir.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Breath")
                {
                    lblBreathSounds.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BrVes")
                {
                    lblVesicularBS.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BrAbn")
                {
                    lblSbnormal.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Edema")
                {
                    lblEdema.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-EdmAbs")
                {
                    lblEdema1.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-EdmPres")
                {
                    lblEdema2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Mstatus")
                {
                    lblMentalStatus.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-MstOr")
                {
                    tbxMental1.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-MstAbn")
                {
                    tbxMental2.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Pain")
                {
                    lblpain.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-PainAbs")
                {
                    lblAbsentPain.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-PainPre")
                {
                    lblPresentPain.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-GpFist")
                {
                    lblFistula1.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Bruit")
                {
                    lblBruitPrepara.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BruitPre")
                {
                    lblPresentBruit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BruitAbn")
                {
                    lblAbnormalBruit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Thrill")
                {
                    lblThrillPrepara.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-ThrillPre")
                {
                    lblPresentThril.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-ThrillAbn")
                {
                    lblAbnormalThrill.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-GpCath")
                {
                    lblCathether.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Cathcare")
                {
                    lblCareCompleted.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Cathcareyes")
                {
                    lblCareYes.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Cathcareno")
                {
                    lblCareNo.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Cathinst")
                {
                    lblInstillation.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-VDW")
                {
                    lblVariDryWt.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-VTUF")
                {
                    lblVarUF.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Instvolart")
                {
                    lblArt.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Instvolven")
                {
                    lblVen.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Instvolml")
                {
                    lblInsML.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Dress")
                {
                    lblDressing.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Dressyes")
                {
                    lblDressYes.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Dressno")
                {
                    lblDressNo.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Dresschg")
                {
                    lblDressingChanges.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-GpPostData-1")
                {
                    lblPostData.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-End")
                {
                    lblEndtime.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Endfmt")
                {
                    lblEndUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Endby")
                {
                    lblEndby.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Inttime")
                {
                    lblInterrupted.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Inttimefmt")
                {
                    lblInterrUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Dur")
                {
                    lblActualDuration.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Durmin")
                {
                    lblDurationUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TimeDiff")
                {
                    lblTimeDifference.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TimeDiffmin")
                {
                    lblTimeDiffUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Decrease")
                {
                    lblReasonForDec.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BldRtn")
                {
                    lblBloodRetur.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BldRtnyes")
                {
                    lblBloodRetuYes.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-BldRtnno")
                {
                    lblBloodRetNo.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-PostHDCom")
                {
                    lblPostComments.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Dappear")
                {
                    lblDialysisAppr.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Bldstop")
                {
                    lblBledding.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Bldstopmin")
                {
                    lblBleedingUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-VolBld")
                {
                    lblVolBloodLoss.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-VolBldml")
                {
                    lblBloodLossUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TotBld")
                {
                    lblTotalBoold.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TotBld-l")
                {
                    lblTotalUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Hepoff")
                {
                    lblTimeHeparin.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Hepoffmin")
                {
                    lbltimeHeparinUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Dilution")
                {
                    lblHeparinDil.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TotHep")
                {
                    lblTotalHeparin.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TotHepu")
                {
                    lblTotalHepUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TotSal")
                {
                    lblTotalSaline.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TotSalml")
                {
                    lblTSalineUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TotUF")
                {
                    lblTotalFluidRemoved.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-TotUFl")
                {
                    lblTotalFluidRUnit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-NUF")
                {
                    lblNetUF.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-NUFl")
                {
                    lblNetUFunit.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Kt/V")
                {
                    lblKtV.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-KT")
                {
                    lblKtValue.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Mobstat")
                {
                    Label26.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Disch")
                {
                    lblDischarge.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Rcare")
                {
                    lblResponsible.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-NotTx")
                {
                    lblNotAHD.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-NotInv")
                {
                    lblInventory.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-NotBill")
                {
                    lblBilling.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Assessby")
                {
                    lblAssessBy.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-ModBy")
                {
                    lblModifiedprep.Text = item.Language.ToString();
                }
                if (item.FormLabelCode == "Tx-Sc5-Signby")
                {
                    lblSignoff.Text = item.Language.ToString();
                }
                if (item.BPPositionID != 0)
                {
                    DropDownList1.Items.Add(item.BP_Language.ToString());
                }
                if (item.BPPositionID != 0)
                {
                    DropDownList2.Items.Add(item.BP_Language.ToString());
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlAssessBy.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        DropDownList4.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlSignoff.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlResponse.Items.Add(item.Initials.ToString());
                    }
                }
                if (item.Reason_For_DecreaseID != 0)
                {
                    if (item.ReasonForDecrease_Language != "")
                    {
                        ddlReasonForDec.Items.Add(item.ReasonForDecrease_Language.ToString());
                    }

                }
                if (item.MobilityID != 0)
                {
                    ddlMoblity.Items.Add(item.Mobility_Language.ToString());
                }
                if (item.CatheterID != 0)
                {
                    if (item.CatheterID != 0)
                    {
                        ddlInstillation.Items.Add(item.Catheter_Language.ToString());
                    }
                }
                if (item.Dialyser_AppearanceID != 0)
                {
                    if (item.Dialyser_AppearanceID != 0)
                    {
                        DropDownList5.Items.Add(item.Dialyser_Language.ToString());
                    }
                }

                if (item.DischargeDesID != 0)
                {
                    if (item.Discharge_Language != "")
                    {
                        ddlDischarge.Items.Add(item.Discharge_Language.ToString());
                    }
                }
                if (item.User_Id != 0)
                {
                    if (item.Initials != "")
                    {
                        ddlEndby.Items.Add(item.Initials.ToString());
                    }
                }
            }
        }

        public void GetFormDataPost()
        {
            TreatmentID = (int)Session["treatmentID"];
            WebRequest req = WebRequest.Create("http://192.168.1.156/api/FMTXPostHD?HDTreatmentID=" + TreatmentID);
            req.ContentType = "application/json";
            WebResponse resp = req.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader re = new StreamReader(stream);
            String json = re.ReadToEnd();

            JavaScriptSerializer ser = new JavaScriptSerializer();

            var obj = JObject.Parse(json);
            tbxweight.Text = (obj["Post_Weight"]).ToString();  
            tbxweighloss.Text = (obj["Weight_Change"]).ToString();
            tbxbps.Text = (obj["BP_Sys"]).ToString();
            tbxbpd.Text = (obj["BP_Dias"]).ToString();
            TextBox6.Text = (obj["Pulse_Rate"]).ToString();
          // tbxpulse2.Text= (obj["BP_Sys"]).ToString();
            TextBox7.Text = (obj["BP_Sys2"]).ToString();
            TextBox8.Text = (obj["BP_Dias2"]).ToString();
            tbxBPPulse4.Text = (obj["Pulse_Rate2"]).ToString();
            tbxTemp2.Text = (obj["Temperature"]).ToString();
            tbxRespire2.Text = (obj["Respiration_Rate"]).ToString();
            tbxSrt.Text = (obj["PrimingVolArt"]).ToString();
            tbxVen.Text = (obj["PrimingVolVen"]).ToString();
            tbxDressing.Text = (obj["Dressing_Changes"]).ToString();
            tbxPostComments.Text = (obj["Post_HD_Comments"]).ToString();
            tbxEndtime.Text = (obj["End_Time2"]).ToString();
            //tbxInterrupted.Text = (obj["Dressing_Changes"]).ToString();
            TextBox11.Text = (obj["Actual_Dialysis_Duration_Run"]).ToString();
            //duration
            tbxtimeDiff.Text = (obj["Dialysis_Time_Difference"]).ToString();
           // tbxDialysAppr.Text = (obj["Dialyser_Appearance"]).ToString();
            tbxBleeding.Text = (obj["Bleeding_Stopped"]).ToString();
            tbxVolBloddLoss.Text = (obj["VolBloodLoss"]).ToString();
            tbxTotalBlood.Text = (obj["Total_Blood_Processed"]).ToString();
            tbxctimeHeparin.Text = (obj["Time_Heparin_Turn_Off"]).ToString();
            tbxHeparinDL.Text = (obj["Total_Heparin_Dilution"]).ToString();
            tbxTotalHep.Text = (obj["Total_Heparin_Units"]).ToString();
            tbxTotalSaline.Text = (obj["Total_Saline"]).ToString();
            tbxTotFluidRemoved.Text = (obj["Total_Fluid_Removed"]).ToString();
            tbxNetUF.Text = (obj["Net_UF"]).ToString();
            tbxVarDryWt.Text = (obj["Variance_frm_Target_Weight"]).ToString();
            tbxVarUF.Text = (obj["Variance_frm_Target_UF"]).ToString();
            tbxKtValue.Text = (obj["KT"]).ToString();
            tbxKtV.Text = (obj["Kt_V"]).ToString();

            //checkboxes

            if (obj["isUnfitWeight"].ToString() == "true")
            {
                unfit2.Checked = true;
            }
            if (obj["Pulse_Rhythm"].ToString() == "Regular")
            {
                cbpulse1.Checked = true;
            }
            else if (obj["Pulse_Rhythm"].ToString() == "Irregular")
            {
                cbpulse2.Checked = true;
            }

            if (obj["Breath_Sounds"].ToString() == "Vesicular")
            {
                cbbreath1.Checked = true;
            }
            else if (obj["Breath_Sounds"].ToString() == "Abonormal")
            {
                cbbreath2.Checked = true;
            }

            if (obj["Edema"].ToString() == "Absent")
            {
                cbedme1.Checked = true;
            }
            else if (obj["Edema"].ToString() == "Present")
            {
                cbedme2.Checked = true;
            }

            if (obj["Mental_Status"].ToString() == "Oriented")
            {
                cbmentalstatus1.Checked = true;
            }
            else if (obj["Mental_Status"].ToString() == "Abonormal")
            {
                cbmentalstatus2.Checked = true;
            }


            if (obj["Pain"].ToString() == "Absent")
            {
                cbpain1.Checked = true;
            }
            else if (obj["Pain"].ToString() == "Present")
            {
                cbpain2.Checked = true;
            }

            if (obj["Bruit"].ToString() == "Present")
            {
                cbBruitpre1.Checked = true;
            }
            else if (obj["Bruit"].ToString() == "Abonormal")
            {
                cbBruitpre2.Checked = true;
            }

            if (obj["Thrill"].ToString() == "Present")
            {
                cbThrillpre1.Checked = true;
            }
            else if (obj["Thrill"].ToString() == "Abonormal")
            {
                cbthrillPre2.Checked = true;
            }

            if (obj["Catheter_Care_Completed"].ToString() == "Yes")
            {
                cbCare1.Checked = true;
            }
            else if (obj["Catheter_Care_Completed"].ToString() == "No")
            {
                cbCare2.Checked = true;
            }

            if (obj["Dressing_Applied"].ToString() == "Yes")
            {
                cbDress1.Checked = true;
            }
            else if (obj["Dressing_Applied"].ToString() == "No")
            {
                cbDress2.Checked = true;
            }

            if (obj["Includes_As_HD_Treatment"].ToString() == "true")
            {
                cbNot1.Checked = true;
            }


            if (obj["Blood_Returned"].ToString() == "Yes")
            {
                cbBlood1.Checked = true;
            }
            else if (obj["Blood_Returned"].ToString() == "No")
            {
                cbBlood2.Checked = true;
            }

            if (obj["Blood_Returned"].ToString() == "Yes")
            {
                cbBlood1.Checked = true;
            }
            else if (obj["Blood_Returned"].ToString() == "No")
            {
                cbBlood2.Checked = true;
            }


            //if (obj["Blood_Returned"].ToString() == "Yes")
            //{
            //    cbInven.Checked = true;
            //}
            if (obj["Bill_Treatment"].ToString() == "No")
            {
                cbInventory2.Checked = true;
            }


            WebRequest req1 = WebRequest.Create("http://192.168.1.156/api/FMTXPostHDLabel?LanguageID=" + language);
            req1.ContentType = "application/json";
            WebResponse resp1 = req1.GetResponse();
            Stream stream1 = resp1.GetResponseStream();
            StreamReader re1 = new StreamReader(stream1);
            String json1 = re1.ReadToEnd();
            // json = "{\"FMTXPreHDLabel\":" + json + "}";
            JavaScriptSerializer ser1 = new JavaScriptSerializer();
            List<FMTXPostHDLabel> keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPostHDLabel>>(json1);

            int bpposition = Convert.ToInt32(obj["BP_Position"]);
            int bposition2 = Convert.ToInt32(obj["BP_Position2"]);
            int moblity = Convert.ToInt32(obj["Mobility_Status"]);
            int discharge = Convert.ToInt32(obj["Discharge_Destination"]);
            int responsible = Convert.ToInt32(obj["Responsible_For_Car"]);
            int reason = Convert.ToInt32(obj["Reason_For_Decrease"]);
            int assessby = Convert.ToInt32(obj["AssessmentBy"]);
            int modified = Convert.ToInt32(obj["Modified_By"]);
            int signoff = Convert.ToInt32(obj["Signed_Off"]);

            foreach (var item in keysWrapper)
            {
                if (item.BPPositionID == bpposition && bpposition !=0)
                {
                    DropDownList1.Text = item.BP_Language.ToString();
                }
                if (item.BPPositionID == bposition2 && bposition2 != 0)
                {
                    DropDownList2.Text = item.BP_Language.ToString();
                }
                if (item.MobilityID == moblity && moblity != 0)
                {
                    ddlMoblity.Text = item.Mobility_Language.ToString();
                }
                if (item.DischargeDesID == discharge && discharge != 0)
                {
                    ddlDischarge.Text = item.Discharge_Language.ToString();
                }
                if (item.User_Id == responsible && responsible != 0)
                {
                    ddlResponse.Text = item.Initials.ToString();
                }
                if(item.Reason_For_DecreaseID == reason && reason !=0)
                {
                    ddlReasonForDec.Text = item.ReasonForDecrease_Language.ToString();
                }
                if(item.User_Id == assessby && assessby !=0)
                {
                    ddlAssessBy.Text = item.Initials.ToString();
                }
                if(item.User_Id == modified && modified !=0)
                {
                    DropDownList4.Text = item.Initials.ToString();
                }
                if(item.User_Id == signoff && signoff !=0)
                {
                    ddlSignoff.Text = item.Initials.ToString();
                }

            }

            DateAssessBy.Value = Convert.ToDateTime(obj["AssessmentDate"]).ToString();
            ModifiedDate.Value = Convert.ToDateTime(obj["Modified_DateTime"]).ToString();
            datesignoff.Value = Convert.ToDateTime(obj["Signed_Off_Date_Time"]).ToString();


            
        }


        protected void Update(object sender, ImageClickEventArgs e)
        {

            FMTXPreHD data = new FMTXPreHD();
            data.HDTreatmentID = TreatmentID;
            data.Weight = Convert.ToDecimal(TextBox1.Text);

            if (unift.Checked == true)
            {
                data.isUnfitWeight = true;
            }

            data.BP_sys = Convert.ToInt32(tbxbp1.Text);
            data.BP_dias = Convert.ToInt32(tbxbp2.Text);
            // data.BP_Position = (long)Convert.ToInt64(ddlBP.SelectedValue);
            data.Pulse_Rate = Convert.ToInt32(tbxpulse1.Text);
            if (regular.Checked == true)
            {
                data.Pulse_Rhythm = "Regular";
            }
            else if (irregular.Checked == true)
            {
                data.Pulse_Rhythm = "Irregular";
            }

            data.BP_sys2 = Convert.ToInt32(tbxbppulse1.Text);
            data.BP_dias2 = Convert.ToInt32(tbxbppulse2.Text);
            data.Pulse_Rate2 = Convert.ToInt32(tbxbppulse3.Text);
            //  data.BP_Position2 = (long)Convert.ToInt64(ddlbpPulse.SelectedValue);
            data.Temperature = Convert.ToDecimal(TextBox2.Text);
            data.Respiration_Rate = Convert.ToInt32(tbxrespiration.Text);
            if (cbVesicular.Checked == true)
            {
                data.Breath_sounds = "Vesicular";
            }
            else if (Abnormal.Checked == true)
            {
                data.Breath_sounds = "Abnormal";
            }
            if (Absent.Checked == true)
            {
                data.Edema = "Absent";
            }
            else if (Present.Checked == true)
            {
                data.Edema = "Present";
            }
            if (Oriented.Checked == true)
            {
                data.Mental_status = "Oriented";
            }
            else if (Abnormalmental.Checked == true)
            {
                data.Mental_status = "Abnormal";
            }

            if (AbsentPain.Checked == true)
            {
                data.Pain = "Absent";
            }
            else if (painPresent.Checked == true)
            {
                data.Pain = "Present";
            }

            if (ICno.Checked == true)
            {
                data.Interdialysis_Complaint = "No";
            }
            else if (ICYes.Checked == true)
            {
                data.Interdialysis_Complaint = "Yes";
            }

            if (cbBruit1.Checked == true)
            {
                data.Bruit = "Present";
            }
            else if (cbBruit2.Checked == true)
            {
                data.Bruit = "Abnormal";
            }

            if (cbThrill1.Checked == true)
            {
                data.Thrill = "Present";
            }
            else if (cbThrill2.Checked == true)
            {
                data.Thrill = "Abnormal";
            }

            if (cbInfection1.Checked == true)
            {
                data.AccessLimb = "Present";
            }
            else if (cbInfection2.Checked == true)
            {
                data.AccessLimb = "Abnormal";
            }

            data.Needle_Gauge_Arterial = TextBox3.Text;
            data.Needle_Gauge_Venous = TextBox4.Text;
            data.CannualationAttempts = tbxcannuation.Text;
            data.Target_Weight = Convert.ToDecimal(tbxDryWeight.Text);
            data.Target_UF = Convert.ToDecimal(TextBox5.Text);
            data.Weight_Changge = Convert.ToDecimal(tbxweightchange.Text);
            data.Planned_fluid_intake = Convert.ToInt32(tbxpfi.Text);
            data.weightLoss = Convert.ToDecimal(tbxweighloss.Text);
            data.Dialysis_Duration = Convert.ToDecimal(tbxDuration.Text);
            data.saline = Convert.ToInt32(tbxsaline.Text);
            data.total_fluid_removal = Convert.ToInt32(tbctfr.Text);
            data.Weight_Changge = Convert.ToDecimal(tbxweightchange.Text);
            data.Blood_Flow = Convert.ToInt32(tbxbf.Text);
            data.UF = Convert.ToInt32(tbxUF.Text);
            data.Dialysis_Flow = Convert.ToInt32(tbxdialysis.Text);

            if (cbClotsYes.Checked == true)
            {
                data.Cather_Art_Clots = "Yes";
            }
            else if (cbClotsAN.Checked == true)
            {
                data.Cather_Art_Clots = "No";
            }



            if (cbClotsVY.Checked == true)
            {
                data.Cather_Ven_Clots = "Yes";
            }
            else if (cbClotsVN.Checked == true)
            {
                data.Cather_Ven_Clots = "No";
            }

            if (cbpatentAY.Checked == true)
            {
                data.Cather_Art_Patent = "Yes";
            }
            else if (cbpatentAN.Checked == true)
            {
                data.Cather_Art_Patent = "No";
            }

            if (cbpatentVY.Checked == true)
            {
                data.Cather_Ven_Patent = "Yes";
            }
            else if (cbpatentVN.Checked == true)
            {
                data.Cather_Ven_Patent = "No";
            }

            if (cbCleanDry.Checked == true)
            {
                data.IsCather_ExitSite_Clean = true;
            }

            if (cbRedness.Checked == true)
            {
                data.IsCather_ExitSite_Redness = true;
            }

            if (cbDischages.Checked == true)
            {
                data.IsCather_ExitSite_Discharges = true;
            }

            if (cbOthers.Checked == true)
            {
                data.IsCather_ExitSite_Others = true;
            }

            if (cbFlowN.Checked == true)
            {
                data.Cather_Flow = "Normal";
            }
            else if (cbfLOWf.Checked == true)
            {
                data.Cather_Flow = "Reverse";
            }

            //data.Date_Insertion = Convert.ToDateTime(DateForInsertion.Value);


            data.Investigation = tbxinvest.Text;
            if (cbDone.Checked == true)
            {
                data.IsDoneInvestigation = true;
            }

            data.ReasonsForNotDone = tbxreasonNot.Text;
            data.pre_comments = tbxComments.Text;

         

            WebRequest req1 = WebRequest.Create("http://192.168.1.156/api/FMTXPreHDLabel?LanguageID=" + language);
            req1.ContentType = "application/json";
            WebResponse resp1 = req1.GetResponse();
            Stream stream1 = resp1.GetResponseStream();
            StreamReader re1 = new StreamReader(stream1);
            String json1 = re1.ReadToEnd();
            // json = "{\"FMTXPreHDLabel\":" + json + "}";
            JavaScriptSerializer ser1 = new JavaScriptSerializer();
            List<FMTXPreHDLabel> keysWrapper = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPreHDLabel>>(json1);

            

            string AccessSite1 = DDL1stSite.SelectedValue;
            string AccessSite2 = ddl2ndsite.SelectedValue;
            string AccessType1 = DDL1stType.SelectedValue;
            string AccessType2 = ddl2ndtype.SelectedValue;
            string AssessBy = ddlAssementby.SelectedValue;
            string modifiedby = ddlModified.SelectedValue;
            string mobility = ddlMonility.SelectedValue;
            string bp = ddlBP.SelectedValue;
            string bppulse = ddlbpPulse.SelectedValue;


            foreach (var item in keysWrapper)
            {
                if (item.Access_Site_Language == AccessSite1)
                {
                    data.Access_Site1ID = item.Access_SiteID;
                }
               
                if (item.Access_Site_Language == AccessSite2)
                {
                    data.Access_Site2ID = item.Access_SiteID;
                }
                if (item.Access_Type_Language == AccessType1)
                {
                    data.Access_Type1ID = item.Access_TypeID;
                }
                if (item.Access_Type_Language == AccessType2)
                {
                    data.Access_Type2ID = item.Access_TypeID;
                }
                if (item.Initials == AssessBy)
                {
                    data.Assessment_by = item.User_Id;
                }
                if (item.Initials == modifiedby)
                {
                    data.Modified_By = item.User_Id;
                }
                if (item.Mobility_Language == mobility)
                {
                    data.Mobility = item.MobilityID;
                }
                if (item.BP_Language == bp)
                {
                    data.BP_Position = item.BPPositionID;
                }
                if (item.BP_Language == bppulse)
                {
                    data.BP_Position2 = item.BPPositionID;
                }
                

            }




           //Update
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("http://192.168.1.156/");
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = client.PostAsJsonAsync("api/FMTXPreHD", data).Result;
           



            //Preparatory Update

            FMTXPreparatory pre = new FMTXPreparatory();

            pre.HDTreatmentID = TreatmentID;
            pre.ROWater = tbxRO.Text;
            pre.UseNo = Convert.ToInt32(tbxuseno.Text);
            pre.Dialyser_ReuseNo = Convert.ToInt32(tbxmax.Text);
            pre.DialysateAconc = tbxconA.Text;
            pre.Dialysis_Flow = Convert.ToInt32(tbxflow.Text);
            pre.DialysateBconc = tbxConB.Text;

            if (cbCFYes.Checked == true)
            {
                pre.Counter_Flow = "Yes";
            }
            else if (cbCFNo.Checked == true)
            {
                pre.Counter_Flow = "No";
            }

            pre.Dialysate_Temp = Convert.ToDecimal(tbxTemperature.Text);
            pre.Dialysate_PH = Convert.ToDecimal(tbxPH.Text);
            pre.Conductivity = Convert.ToDecimal(tbxcondu.Text);

            if (cbpreprocess.Checked == true)
            {
                pre.IsDialyserPreProcess = true;
            }
            else if (cbtreatment.Checked == true)
            {
                pre.IsDialyserPreTreat = true;
            }

            if (cbAlarmTest.Checked == true)
            {
                pre.Alarm_Tests = "Pass";
            }

            if (cbPressure.Checked == true)
            {
                pre.Dialyser_Pressure_Test = "Pass";
            }

            if (cbTypeYes.Checked == true)
            {
                pre.IsPrime = true;
            }
            else if (cbTypeNo.Checked == true)
            {
                pre.IsPrime = false;
            }

            pre.Actual_Heparin_bolus = Convert.ToInt32(tbxload.Text);
            pre.Heparine_Mid_Dose = Convert.ToInt32(tbxloadmid.Text);

            if (tbxtime.Text != "")
            {
                pre.HD_Run_Bolus_Time = Convert.ToDateTime(tbxtime.Text);
            }

            if (tbxtimeMid.Text != "")
            {
                pre.HD_Run_MidDose_Time = Convert.ToDateTime(tbxtimeMid.Text);
            }
            

            if (cbPriprPositive.Checked == true)
            {
                pre.Disinfectant_Prior_To_Rinse = "Positive";
            }

            if (cbNegative1.Checked == true)
            {
                pre.Residual_Disinfectant_Test = "Negative";
            }

            if (cbMachineNA.Checked == true)
            {
                pre.Residual_Machine_Test = "";

            }
            else if (cbNegative2.Checked == true)
            {
                pre.Residual_Machine_Test = "Negative";
            }

            if (cbNegativeBlood.Checked == true)
            {
                pre.Residual_Bloodline_Test = "Negative";
            }

            if (cbsalineNegative.Checked == true)
            {
                pre.Residual_SalineBag_Test = "Negative";
            }

            if (tbxStartTime.Text != "")
            {
                pre.HD_Run_Start_time = Convert.ToDateTime(tbxStartTime.Text);
            }

           
            pre.HDMac_Comments = tbxprepComments.Text;
            //if (cbcompleteby.Checked == true)
            //{
               
            //}
            if (tbxTimeChange.Text != "")
            {
                pre.Time_Changed_Machine = Convert.ToDateTime(tbxTimeChange.Text);
            }
            if (tbxTimeChange2.Text != "")
            {
                pre.Time_Changed_dialyser = Convert.ToDateTime(tbxTimeChange2.Text);
            }
           
           

            //dropdownlist


            WebRequest req2 = WebRequest.Create("http://192.168.1.156/api/FMTXPreparatoryLabel?LanguageID=" + language);
            req2.ContentType = "application/json";
            WebResponse resp2 = req2.GetResponse();
            Stream stream2 = resp2.GetResponseStream();
            StreamReader re2 = new StreamReader(stream2);
            String json2 = re2.ReadToEnd();
            
            JavaScriptSerializer ser2 = new JavaScriptSerializer();
            List<FMTXPreparatoryLabel> keysWrapper2 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPreparatoryLabel>>(json2);

            string station = ddlstation.SelectedValue;
            string machine = ddlMachineID.SelectedValue;
            string type = DropDownList3.SelectedValue;
            string schedule = ddlSchedule.SelectedValue;
            string shift = ddlShift.SelectedValue;
            string dialyser = ddldialyser.SelectedValue;
            string dialysate = ddldialysate.SelectedValue;
            string reuse = ddlReuse.SelectedValue;
            string alarmtestCheck = ddlalarmCheck.SelectedValue;
            string pressurecheck = ddlpressureCheckby.SelectedValue;
            string mannualcheck = ddlManualCheck.SelectedValue;
            string antitype = ddlAntiType.SelectedValue;
            string preparabyBolus = ddlpreparebybou.SelectedValue;
            string preparaMid = ddlpreparebyMid.SelectedValue;
            string giveBolus = ddlGivenByBolu.SelectedValue;
            string giveMid = ddlGivenByMid.SelectedValue;
            string witenessBolus = ddlwitessblous.SelectedValue;
            string witenessMid = ddlwitenessMid.SelectedValue;
            string proirCheck = ddlPositiveCheckby.SelectedValue;
            string dialysateCheck = ddlNegativeCheck.SelectedValue;
            string machineCheck = ddlNegative2Check.SelectedValue;
            string blood = ddlNegative3Check.SelectedValue;
            string saline = ddlSalineNegativeCheck.SelectedValue;
            string correct = ddlCorrect.SelectedValue;
            string witenessBy = ddlWitessnessby.SelectedValue;
            string prime = ddlprimedby.SelectedValue;
            string commence = ddlCommencedBy.SelectedValue;
            string completeby = ddlCompleteby.SelectedValue;
            string modified = ddlModifiedBy.SelectedValue;
            string machine2 = ddl2ndMachineID.SelectedValue;
            string dialyser2 = dd2ndDialyser.SelectedValue;
            string reason = ddlReasonForchange.SelectedValue;
            string change = ddlChangeby.SelectedValue;


            foreach (var item in keysWrapper2)
            {
                if (item.Chair_Name == station)
                {
                    pre.Chair = item.ChairID;
                }

                if (item.MachineID2 == machine)
                {
                    pre.MachineCode = item.MachineCodeID;
                }
                if (item.Machine_Language == type)
                {
                    pre.Machine_Type = item.MachineID;
                }
                if (item.Schedule_Frequency == schedule)
                {
                    pre.Schedule = item.ScheduleID;
                }
                if (item.Shift == shift)
                {
                    pre.Shift = item.ShiftID;
                }

                if (item.Dialyser_Name == dialyser)
                {
                    pre.First_Dialyser = item.DialyserID;
                }
                if (item.Dialysate_Name == dialysate)
                {
                    pre.First_Dialysate = item.DialysateID;
                }
                if (item.Initials == reuse)
                {
                    pre.Reuse_Tech = item.User_Id;
                }
                if (item.Initials == alarmtestCheck)
                {
                    pre.AlarmTest_CheckBy = item.User_Id;
                }
                if (item.Initials == pressurecheck)
                {
                    pre.DPTTest_CheckBy = item.User_Id;
                }
                if (item.Initials == mannualcheck)
                {
                    pre.MP_CheckBy = item.User_Id;
                }
                if (item.HepLanguage == antitype)
                {
                    pre.HeparineType = item.HepTypeID;
                }
                if (item.Initials == preparabyBolus)
                {
                    pre.Bolus_Prepared_By = item.User_Id;
                }
                if (item.Initials == preparaMid)
                {
                    pre.MidDose_Prepared_By = item.User_Id;
                }
                if (item.Initials == giveBolus)
                {
                    pre.Bolus_Administered_By = item.User_Id;
                }
                if (item.Initials == giveMid)
                {
                    pre.MidDose_Administered_By = item.User_Id;
                }
                if (item.Initials == witenessBolus)
                {
                    pre.Bolus_Witnessed_By = item.User_Id;
                }
                if (item.Initials == proirCheck)
                {
                    pre.DPR_CheckBy = item.User_Id;
                }
                if (item.Initials == dialysateCheck)
                {
                    pre.RDT_CheckBy = item.User_Id;
                }
                if (item.Initials == machineCheck)
                {
                    pre.Residual_Machine_CheckedBy = item.User_Id;
                }
                if (item.Initials == blood)
                {
                    pre.Residual_Bloodline_CheckedBy = item.User_Id;
                }
                if (item.Initials == saline)
                {
                    pre.Residual_SalineBag_CheckedBy = item.User_Id;
                }
                if (item.Initials == correct)
                {
                    pre.Dialyser_Patient_ID_Match = item.User_Id;
                }
                if (item.Initials == witenessBy)
                {
                    pre.DialyserCheck_WitnessBy = item.User_Id;
                }
                if (item.Initials == prime)
                {
                    pre.PrimedBy = item.User_Id;
                }
                if (item.Initials == commence)
                {
                    pre.DialysedBy = item.User_Id;
                }
                if (item.Initials == completeby)
                {
                    pre.Completed_By = item.User_Id;
                }
                if (item.Initials == modified)
                {
                    pre.Modified_By = item.User_Id;
                }
                if (item.MachineID2 == machine2)
                {
                    pre.Second_Machine_ID = item.MachineCodeID;
                }
                if (item.Dialyser_Name == dialyser2)
                {
                    pre.Second_Dialyser = item.DialyserID;
                }
                if (item.Reason_Language == reason)
                {
                    pre.ReasonForChanged = item.ReasonID;
                }
                if (item.Initials == change)
                {
                    pre.ChagedBy = item.User_Id;
                }
            }

            HttpClient client1 = new HttpClient();
            client1.BaseAddress = new Uri("http://192.168.1.156/");
            client1.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response1 = client1.PostAsJsonAsync("api/FMTXPreparatory", pre).Result;




            //PostHD update

            FMTXPostHD Post = new FMTXPostHD();
            Post.HDTreatmentID = TreatmentID;
            Post.Post_Weight = Convert.ToDecimal(tbxweight.Text);
            Post.Weight_Change = Convert.ToDecimal(tbxweighloss.Text);
            Post.BP_Sys = Convert.ToInt32(tbxbps.Text);
            Post.BP_Dias = Convert.ToInt32(tbxbpd.Text);
            Post.Pulse_Rate = Convert.ToInt32(TextBox6.Text);

            if (cbpulse1.Checked == true)
            {
                Post.Pulse_Rhythm = "Regular";
            }
            else if (cbpulse2.Checked == true)
            {
                Post.Pulse_Rhythm = "Irregular";
            }

            Post.BP_Sys2 = Convert.ToInt32(TextBox7.Text);
            Post.BP_Dias2 = Convert.ToInt32(TextBox8.Text);
            Post.Pulse_Rate2 = Convert.ToInt32(tbxBPPulse4.Text);

            Post.Temperature = Convert.ToDecimal(tbxTemp2.Text);
            Post.Respiration_Rate = Convert.ToInt32(tbxRespire2.Text);

            if (cbbreath1.Checked == true)
            {
                Post.Breath_Sounds = "Vesicular";
            }
            else if (cbbreath2.Checked == true)
            {
                Post.Breath_Sounds = "Abnormal";
            }

            if (cbedme1.Checked == true)
            {
                Post.Edema = "Absent";
            }
            else if (cbedme2.Checked == true)
            {
                Post.Edema = "Present";
            }

            if (cbmentalstatus1.Checked == true)
            {
                Post.Mental_Status = "Oriented";
            }
            else if (cbmentalstatus2.Checked == true)
            {
                Post.Mental_Status = "Abnormal";
            }

            if (cbpain1.Checked == true)
            {
                Post.Pain = "Absent";
            }
            else if (cbpain2.Checked == true)
            {
                Post.Pain = "Present";
            }

            if (cbBruitpre1.Checked == true)
            {
                Post.Bruit = "Present";
            }
            else if (cbBruitpre2.Checked == true)
            {
                Post.Bruit = "Abnormal";
            }

            if (cbThrillpre1.Checked == true)
            {
                Post.Thrill = "Present";
            }
            else if (cbthrillPre2.Checked == true)
            {
                Post.Thrill = "Abnormal";
            }

            if (cbCare1.Checked == true)
            {
                Post.Catheter_Care_Completed = "Yes";
            }
            else if (cbCare2.Checked == true)
            {
                Post.Catheter_Care_Completed = "No";
            }

            Post.PrimingVolArt = Convert.ToDecimal(tbxSrt.Text);
            Post.PrimingVolVen = Convert.ToDecimal(tbxVen.Text);

            if (cbDress1.Checked == true)
            {
                Post.Dressing_Applied = "Yes";
            }
            else if (cbDress2.Checked == true)
            {
                Post.Dressing_Applied = "No";
            }

            Post.Dressing_Changes = Convert.ToInt32(tbxDressing.Text);

            if (cbNot1.Checked == true)
            {
                Post.Includes_As_HD_Treatment = true;
            }

            if (cbInventory2.Checked == true)
            {
                Post.Bill_Treatment = true;
            }

            Post.Post_HD_Comments = tbxPostComments.Text;
            if (tbxEndtime.Text != "")
            {
                Post.End_Time = Convert.ToDateTime(tbxEndtime.Text);
            }
            
            Post.Actual_Dialysis_Duration_Run = Convert.ToInt32(TextBox11.Text);
            Post.Dialysis_Time_Difference = Convert.ToInt32(tbxtimeDiff.Text);
            if (cbBlood1.Checked == true)
            {
                Post.Blood_Returned = "Yes";
            }
            else if (cbBlood2.Checked == true)
            {
                Post.Blood_Returned = "No";
            }

           // Post.Dialyser_Appearance = Convert.ToInt32(tbxDialysAppr.Text);
            Post.Bleeding_Stopped = Convert.ToInt32(tbxBleeding.Text);
            Post.VolBloodLoss = Convert.ToDecimal(tbxVolBloddLoss.Text);
            Post.Total_Blood_Processed = Convert.ToDecimal(tbxTotalBlood.Text);
            Post.Time_Heparin_Turn_Off = Convert.ToInt32(tbxctimeHeparin.Text);
            Post.Total_Heparin_Dilution = Convert.ToInt32(tbxHeparinDL.Text);
            Post.Total_Heparin_Units = Convert.ToInt32(tbxTotalHep.Text);
            Post.Total_Saline = Convert.ToInt32(tbxTotalSaline.Text);
            Post.Total_Fluid_Removed = Convert.ToInt32(tbxTotFluidRemoved.Text);
            Post.Net_UF = Convert.ToInt32(tbxNetUF.Text);
            Post.Variance_frm_Target_Weight = Convert.ToDecimal(tbxVarDryWt.Text);
            Post.Variance_frm_Target_UF = Convert.ToDecimal(tbxVarUF.Text);
            Post.KT = Convert.ToDecimal(tbxKtValue.Text);
            Post.Kt_V = Convert.ToDecimal(tbxKtV.Text);

            //if (cbAssess.Checked == true)
            //{

            //}
            if (DateAssessBy.Value != "")
            {
                Post.AssessmentDate = Convert.ToDateTime(DateAssessBy.Value);
            }

            if (ModifiDate.Value != "")
            {
                Post.Modified_DateTime = Convert.ToDateTime(ModifiDate.Value);
            }

            if (datesignoff.Value != "")
            {
                Post.Signed_Off_Date_Time = Convert.ToDateTime(datesignoff.Value);
            }
            


            WebRequest req3 = WebRequest.Create("http://192.168.1.156/api/FMTXPostHDLabel?LanguageID=" + language);
            req3.ContentType = "application/json";
            WebResponse resp3 = req3.GetResponse();
            Stream stream3 = resp3.GetResponseStream();
            StreamReader re3 = new StreamReader(stream3);
            String json3 = re3.ReadToEnd();

            JavaScriptSerializer ser3 = new JavaScriptSerializer();
            List<FMTXPostHDLabel> keysWrapper3 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FMTXPostHDLabel>>(json3);

            string bpposition = DropDownList1.SelectedValue;
            string bpposition2 = DropDownList2.SelectedValue;
            string instillaton = ddlInstillation.SelectedValue;
            string moblility = ddlMoblity.SelectedValue;
            string discharge = ddlDischarge.SelectedValue;
            string responsible = ddlResponse.SelectedValue;
            string endby = ddlEndby.SelectedValue;
            string reason1 = ddlReasonForDec.SelectedValue;
            string assessby = ddlAssessBy.SelectedValue;
            string modifiedpost = DropDownList4.SelectedValue;
            string signoff = ddlSignoff.SelectedValue;

            foreach (var item in keysWrapper3)
            {
                if (item.BP_Language == bpposition)
                {
                    Post.BP_Position = item.BPPositionID;
                }
                if (item.BP_Language == bpposition2)
                {
                    Post.BP_Position2 = item.BPPositionID;
                }
                if (item.Mobility_Language == moblility)
                {
                    Post.Mobility_Status = item.MobilityID;
                }
                if (item.Discharge_Language == discharge)
                {
                    Post.Discharge_Destination = item.DischargeDesID;
                }
                if (item.Initials == responsible)
                {
                    Post.Responsible_For_Car = item.User_Id;
                }
                if (item.Initials == endby)
                {
                    Post.Ended_By = item.User_Id;
                }
                if (item.ReasonForDecrease_Language == reason1)
                {
                    Post.Reason_For_Decrease = item.Reason_For_DecreaseID;
                }
                if (item.Initials == assessby)
                {
                    Post.AssessmentBy = item.User_Id;
                }
                if (item.Initials == modifiedpost)
                {
                    Post.Modified_By = item.User_Id;
                }
                if (item.Initials == signoff)
                {
                    Post.Signed_Off = item.User_Id;
                }
            }


            HttpClient client2 = new HttpClient();
            client2.BaseAddress = new Uri("http://192.168.1.156/");
            client2.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response2 = client2.PostAsJsonAsync("api/FMTXPostHD", Post).Result;

            if (response2.IsSuccessStatusCode)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "UserDialogScript", "alert(\"User successfully updated\");", true);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "UserDialogScript", "alert(\"User update Fail\");", true);
            }


        }

        protected void ImageButton9_Click(object sender, ImageClickEventArgs e)
        {
            
            
                ScriptManager.RegisterStartupScript(this, this.GetType(), "windowScript", "popupUploadForm()", true);
         
           
        }

       

        
    }
}